import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import "lib-flexible/flexible";


//请求工具
import axios from "axios";
import VueAxios from "vue-axios";
import Viewer from 'v-viewer'
import 'viewerjs/dist/viewer.css'
import VideoPlayer from 'vue-video-player'
import 'vue-video-player/src/custom-theme.css'
import 'video.js/dist/video-js.css'
import { Button,ImagePreview, Icon, Tabbar, TabbarItem, Tab, Tabs,NavBar,Swipe, SwipeItem,Tag,Field,Form,CellGroup,Toast,Search,PullRefresh,Lazyload,List,DropdownMenu, DropdownItem,SwipeCell} from "vant";
Vue.use(Button).use(Icon).use(Tabbar).use(TabbarItem).use(Tab).use(Tabs).use(NavBar).use(Swipe).use(SwipeItem).use(Tag).use(Field).use(CellGroup).use(Form).use(Toast).use(Search).use(PullRefresh).use(List).use(DropdownMenu).use(DropdownItem).use(ImagePreview).use(Lazyload).use(SwipeCell)
Vue.use(Viewer)
Vue.use(VideoPlayer)
Viewer.setDefaults({
  Options: { 'inline': true, 'button': true, 'navbar': true, 'title': true, 'toolbar': true, 'tooltip': true, 'movable': true, 'zoomable': true, 'rotatable': true, 'scalable': true, 'transition': true, 'fullscreen': true, 'keyboard': true, 'url': 'data-source' }
})
// 第一个是videoJs的样式，后一个是vue-video-player的样式，因为考虑到我其他业务组件可能也会用到视频播放，所以就放在了main.js内
require('video.js/dist/video-js.css')
require('vue-video-player/src/custom-theme.css')
// 全局前置守卫
// router.beforeEach(async (to, from) => {
  
//     // 将用户重定向到登录页面
   
  
// })

axios.interceptors.request.use(config => {
  //config: 请求配置(请求头, 请求参数, 请求类型, 请求路径, ....)
  // console.log('发起请求之前执行');

    //启动加载提示
    Toast.loading({
      message: '正在加载中...',
      //禁止穿透点击
      forbidClick: true,
      // loadingType: 'spinner',
      //不会自动关闭提示
      duration: 0,
      // overlay:true,
      // icon: require('./assets/loading.gif'),
    })

  return config;
}, err => {
  console.log('err ==> ', err);
  //关闭加载提示
  Toast.clear();
  return Promise.reject(err);
})

//添加一个响应之前拦截器
axios.interceptors.response.use(res => {
  //res: 服务器响应数据
  // console.log('响应数据返回给前端之前');

  //关闭加载提示
  Toast.clear();

  return res;
}, err => {
  console.log('err ==> ', err);

  //关闭加载提示
  Toast.clear();
  
  return Project.reject(err);
})

Vue.config.productionTip = false

new Vue({
  router,
  render:h=>h(App)
}).$mount('#app')
